var app = getApp()
var db = wx.cloud.database()
Page({

    data: {

    },
    // 删除
    delete_this:function(e){
        console.log(e)
        let _id = e.currentTarget.dataset.id
        console.log(_id)
        wx.showModal({
            title: '注意',
            content: '您将要删除本条记录！',
            showCancel: true,            
            success: function(res) {
                console.log(res.confirm)
                if (res.confirm==true){
                    db.collection('memo').doc(_id).remove({
                        success: function (res) {
                            console.log(res.errMsg =="document.remove:ok")
                            if (res.errMsg == "document.remove:ok"){
                                wx.redirectTo({
                                    url: '/pages/home/list/list',
                                })
                            }
                        }
                    })
                }
            },
            fail: function(res) {},
            complete: function(res) {},
        })
    },
    onLoad: function(options) {
        let that = this;
        let winh = app.globalData.winH;
        let tabbar = app.globalData.tabbar;
        let userinfo = wx.getStorageSync("userInfo")
        console.log(userinfo)
        if (userinfo == "") {
            wx.navigateTo({
                url: '/pages/home/login/login',
            })
        }
        that.setData({
            winh: winh,
            tabbar: tabbar,
            userinfo: userinfo
        })
        //   拿到我提交的东西
        db.collection('memo').where({
            _openid: this.data.openid,

        }).get({
            success: function (res) {
                console.log(res.data)
                let list = res.data.reverse()
                that.setData({
                    list: list
                })
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})